<?php

namespace common\models\datas;

use Yii;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
use yii\helpers\ArrayHelper;

/**
 * This is the model class for table "dmd_cards_batch".
 *
 * @property integer $id
 * @property integer $site_id
 * @property integer $applicant_id
 * @property integer $approver_id
 * @property integer $apply_number
 * @property string $apply_reason
 * @property integer $approver_number
 * @property string $approver_ remark
 * @property integer $card_type
 * @property string $title
 * @property integer $integral
 * @property integer $cash
 * @property integer $grant_time
 * @property integer $number
 * @property integer $ cardno_begin
 * @property integer $cardno_end
 * @property integer $status
 * @property integer $created_at
 * @property integer $updated_at
 * @property integer $is_delete
 */
class CardsBatch extends \common\components\bases\BaseModel
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'dmd_cards_batch';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['site_id', 'applicant_id', 'approver_id', 'card_send','apply_number', 'approver_number', 'card_type', 'integral', 'cash', 'grant_time', 'cardno_begin', 'cardno_end', 'status', 'created_at', 'updated_at', 'is_delete'], 'integer'],
            [['apply_reason', 'approver_remark', 'title'], 'string', 'max' => 255],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('common', '序列'),
            'site_id' => Yii::t('common', '分店id'),
            'applicant_id' => Yii::t('common', '申请人id(关联发卡人信息表)'),
            'approver_id' => Yii::t('common', '审批人id(关联发卡人信息表)'),
            'apply_number' => Yii::t('common', '申请数量'),
            'apply_reason' => Yii::t('common', '申请理由'),
            'approver_number' => Yii::t('common', '发放数量'),
            'approver_remark' => Yii::t('common', '审核描述'),
            'card_type' => Yii::t('common', '卡类型 0:实体卡 1:虚拟红包'),
            'title' => Yii::t('common', '申请批次标题'),
            'integral' => Yii::t('common', '包含积分'),
            'cash' => Yii::t('common', '包含现金'),
            'grant_time' => Yii::t('common', '审核通过时间'),
            'cardno_begin' => Yii::t('common', '开始编号'),
            'cardno_end' => Yii::t('common', '结束编号'),
            'card_send'=> Yii::t('common', '已发卡数量'),
            'status' => Yii::t('common', '审核状态：0:审批中 1:通过 2:未通过'),
            'created_at' => Yii::t('common', '创建时间'),
            'updated_at' => Yii::t('common', '更新时间'),
            'is_delete' => Yii::t('common', '是否删除 0:默认未删除 1:已经删除'),
        ];
    }

    public function getCardsIssuerinfor()
    {
        return $this->hasOne(CardsIssuerinfor::className(), ['id' => 'applicant_id']);
    }

    public function behaviors()
    {
        return ArrayHelper::merge(parent::behaviors(), [
            [
                'class' => TimestampBehavior::className(),
                'attributes' => [
                    ActiveRecord::EVENT_BEFORE_INSERT => ['created_at', 'updated_at'],
                    ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_at'],
                ],
            ],
        ]);
    }
}
